home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / lib / happysrc / pcinit.c < prev    next >
Text File  |  1994-02-05  |  5KB  |  150 lines

  1. /**************************************
  2.  *                                    *
  3.  *    *** HAPPy Pascal compiler ***   *
  4.  *       initialize routine           *
  5.  *                                    *
  6.  *   Copyright (c) H.Asano 1992,1994. *
  7.  **************************************/
  8.  
  9. #define  EXTERN  extern
  10.  
  11. #include <signal.h>
  12. #include "pascomp.h"
  13.  
  14. static void initscalars(void) ;
  15. static void initsets(void)    ;
  16. static void entstdtypes(void) ;
  17. extern void entstdnames(void) ;
  18. extern void entundecl  (void) ;
  19. extern Set  *mkset(Set*,int,...) ;
  20. extern Set  *orset(Set*,Set*) ;
  21. extern void initpcd(void) ;
  22. extern void initheap(void);
  23. extern void *Malloc(int)  ;
  24. extern void real_err(int,int) ;
  25.  
  26. /****************************************/
  27. /* init() :初期設定メイン               */
  28. /****************************************/
  29. void init(void)
  30. {
  31.      signal(SIGFPE,real_err) ;          /* 浮動小数点例外処理の登録   */
  32.      initheap()    ;                    /* heapメモリの初期設定       */
  33.      initscalars() ;                    /* スカラー項目の初期設定     */
  34.      initsets()    ;                    /* symbol set の 初期設定     */
  35.      initpcd()     ;                    /* P-codeの初期設定           */
  36.  
  37.      level = 0 ;
  38.      top   = 0 ;
  39.      display[0].fname  = nil  ;
  40.      display[0].flabel = nil  ;
  41.      display[0].occur  = blck ;
  42.  
  43.      entstdtypes() ;                    /* 標準の型の登録             */
  44.      entstdnames() ;                    /* 標準名の登録               */
  45.      entundecl  () ;                    /* 未定義の名前のための事前処理*/
  46.  
  47.     level = 1 ;                         /* 利用者定義の名前は水準1から*/
  48.     top   = 1 ;
  49.     display[1].fname  = nil  ;
  50.     display[1].flabel = nil  ;
  51.     display[1].occur  = blck ;
  52. }
  53.  
  54. /****************************************/
  55. /* initscalars() : スカラー項目初期設定 */
  56. /****************************************/
  57. static void initscalars(void)
  58. {
  59.      defineinput  = false             ; /* input ファイル 未定義      */
  60.      defineoutput = false             ; /* outputファイル 未定義      */
  61.      errorcount   = 0                 ; /* 発見したエラー数初期化     */
  62.      lineno       = 0                 ; /* ソースの行番号初期化       */
  63.      ic           = 0                 ; /* Pコードカウンタ 0に設定    */
  64.      lc           = outputadr+charmax ; /* 変数カウンタ初期設定       */
  65.      ch           = ' '               ; /* 読込文字初期化             */
  66.      fwptr        = nil               ; /* 前方参照ポインタをクリア   */
  67. }
  68.  
  69. /****************************************/
  70. /* initsets() : 集合の初期設定          */
  71. /****************************************/
  72. static void initsets(void)
  73. {
  74.      mkset(&constbegsys,
  75.            addop,intconst,realconst,stringconst,ident,-1)  ;
  76.      mkset(&simptypebegsys,  lparent,-1)  ;
  77.      orset(&simptypebegsys, &constbegsys) ;
  78.      mkset(&typebegsys,
  79.            arrow,packedsy,arraysy,recordsy,setsy,filesy,-1) ;
  80.      orset(&typebegsys, &simptypebegsys) ;
  81.      mkset(&typedels,
  82.            arraysy,recordsy,setsy,filesy,-1) ;
  83.      mkset(&blockbegsys,
  84.            labelsy,constsy,typesy,varsy,procsy,funcsy,beginsy,-1);
  85.      mkset(&selectsys,
  86.            arrow,period,lbrack,-1) ;
  87.      mkset(&facbegsys,
  88.            intconst,realconst,stringconst,ident,lparent,lbrack,notsy,nilsy,-1);
  89.      mkset(&statbegsys,
  90.            beginsy,gotosy,ifsy,whilesy,repeatsy,forsy,withsy,casesy,-1) ;
  91.      mkset(&statfolsys,
  92.            semicolon,endsy,elsesy,untilsy,-1) ;
  93. }
  94.  
  95. /****************************************/
  96. /* entstdtypes() : 標準の型登録         */
  97. /****************************************/
  98. static void entstdtypes(void)
  99. {
  100.    /**** integer ****/
  101.      intptr = (stp*)Malloc(sizeof(stp)) ;
  102.      intptr->size = intsize ;
  103.      intptr->form = scalar  ;
  104.      intptr->assignflag = true ;
  105.      intptr->sf.sc.scalkind = standard ;
  106.  
  107.   /**** real ****/
  108.      realptr = (stp*)Malloc(sizeof(stp)) ;
  109.      realptr->size = realsize ;
  110.      realptr->form = scalar   ;
  111.      realptr->assignflag = true ;
  112.      realptr->sf.sc.scalkind = standard ;
  113.  
  114.   /**** char ****/
  115.      charptr = (stp*)Malloc(sizeof(stp)) ;
  116.      charptr->size = charsize ;
  117.      charptr->form = scalar   ;
  118.      charptr->assignflag = true ;
  119.      charptr->sf.sc.scalkind = standard ;
  120.  
  121.   /**** boolean ****/
  122.      boolptr = (stp*)Malloc(sizeof(stp)) ;
  123.      boolptr->size = boolsize ;
  124.      boolptr->form = scalar   ;
  125.      boolptr->assignflag = true ;
  126.      boolptr->sf.sc.scalkind = declared ;  /* 列挙型はdeclaredである  */
  127.  
  128.   /**** nil ****/
  129.      nilptr = (stp*)Malloc(sizeof(stp)) ;
  130.      nilptr->size = ptrsize ;
  131.      nilptr->form = pointer ;
  132.      nilptr->assignflag = true  ;
  133.      nilptr->sf.pt.eltype = nil ;
  134.  
  135.   /**** for alignment of parameters ****/
  136.      parmptr = (stp*)Malloc(sizeof(stp)) ;
  137.      parmptr->size = parmsize ;
  138.      parmptr->form = scalar ;
  139.      parmptr->assignflag = true ;
  140.      parmptr->sf.sc.scalkind = standard ;
  141.  
  142.   /**** text ****/
  143.      textptr = (stp*)Malloc(sizeof(stp)) ;
  144.      textptr->size = charsize ;
  145.      textptr->form = files    ;
  146.      textptr->assignflag = false ;
  147.      textptr->sf.fi.texttype = true ;
  148.      textptr->sf.fi.filtype  = charptr ;
  149. }
  150.